package com.bringway.p2p.controller;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import net.sf.json.JSONObject;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import com.bringway.framework.controller.JsonController;
import com.bringway.framework.util.RequestUtils;
import com.bringway.p2p.service.CjjgService;

/**
 * 
 * @author zhai
 * @version 创建时间：2015年12月14日 上午9:34:42
 * @功能：抽奖结果页面
 */


@Controller
@RequestMapping("/cjjg")
public class CjjgController  extends JsonController{


	@Autowired
	private CjjgService cjjgService;
	
	
	/**
	 * 
	 * @param request 获取请求的数据得到查询的数据字段
	 * @param response 存储到Map集合中
	 * @return 数据集合和查询的count数值
	 * @throws Exception
	 */
	@RequestMapping("/queryCjjgList")
	public ModelAndView queryCjjgList(HttpServletRequest request,HttpServletResponse response) throws Exception{
		JSONObject result = new JSONObject();
		JSONObject params = new JSONObject();
		
		Integer page = RequestUtils.getIntParameter(request, "page");//新版本,传参
		Integer start = RequestUtils.getIntParameter(request, "start");
		Integer limit = RequestUtils.getIntParameter(request, "limit");
		if (null!=page) {//新版本,传参
			start=(page-1)*limit;
		}
		String startDate = RequestUtils.getStringParameter(request, "startDate");
		String endDate = RequestUtils.getStringParameter(request, "endDate");
		String username = RequestUtils.getStringParameter(request, "username");
		String sjhm = RequestUtils.getStringParameter(request, "sjhm");
		String jxx = RequestUtils.getStringParameter(request, "jxx");
		String vip_dj = RequestUtils.getStringParameter(request, "vip_dj");

		
		params.put("start", start);
		params.put("limit", limit);
		params.put("startDate", startDate);
		params.put("endDate", endDate);
		params.put("username", username);
		params.put("sjhm", sjhm);
		params.put("jxx", jxx);
		params.put("vip_dj", vip_dj);

		
		
		List list = cjjgService.queryCjjgList(params);
		int count = cjjgService.getCjjgCount(params);
		result.put("data", list);	
		result.put("total", count);
		if (null!=page) {//新版本,传参
			int totalPage=count%limit==0?count/limit:count/limit+1;
			result.put("totalPage", totalPage);
		}
		serialize(request,response,result);
		return null;
	}
	

	/**
	 * 
	 * @param request 获取请求的数据得到查询的数据字段
	 * @param response 存储到Map集合中
	 * @return 数据集合和查询的count数值
	 * @throws Exception
	 */
	@RequestMapping("/queryCjjlList")
	public ModelAndView queryCjjlList(HttpServletRequest request,HttpServletResponse response) throws Exception{
		JSONObject result = new JSONObject();
		JSONObject params = new JSONObject();
		
		Integer page = RequestUtils.getIntParameter(request, "page");//新版本,传参
		Integer start = RequestUtils.getIntParameter(request, "start");
		Integer limit = RequestUtils.getIntParameter(request, "limit");
		String startDate = RequestUtils.getStringParameter(request, "startDate");
		String endDate = RequestUtils.getStringParameter(request, "endDate");
		if (null!=page) {//新版本,传参
			start=(page-1)*limit;
		}
		String username = RequestUtils.getStringParameter(request, "username");
		String sjhm = RequestUtils.getStringParameter(request, "sjhm");
		String cjzt = RequestUtils.getStringParameter(request, "cjzt");
		String lqzt = RequestUtils.getStringParameter(request, "lqzt");
		params.put("start", start);
		params.put("limit", limit);
		params.put("startDate", startDate);
		params.put("endDate", endDate);
		params.put("username", username);
		params.put("sjhm", sjhm);
		params.put("cjzt", cjzt);
		params.put("lqzt", lqzt);
		List list = cjjgService.queryCjjlList(params);
		int count = cjjgService.getCjjlCount(params);
		result.put("data", list);	
		result.put("total", count);
		if (null!=page) {//新版本,传参
			int totalPage=count%limit==0?count/limit:count/limit+1;
			result.put("totalPage", totalPage);
		}
		serialize(request,response,result);
		return null;
	}
	/**
	 * 
	 * @param request 获取请求的数据得到查询的数据字段
	 * @param response 存储到Map集合中
	 * @return 数据集合和查询的count数值
	 * @throws Exception
	 */
	@RequestMapping("/queryCjzgList")
	public ModelAndView queryCjzgList(HttpServletRequest request,HttpServletResponse response) throws Exception{
		JSONObject result = new JSONObject();
		JSONObject params = new JSONObject();
		
		Integer page = RequestUtils.getIntParameter(request, "page");//新版本,传参
		Integer start = RequestUtils.getIntParameter(request, "start");
		Integer limit = RequestUtils.getIntParameter(request, "limit");
		if (null!=page) {//新版本,传参
			start=(page-1)*limit;
		}
		String username = RequestUtils.getStringParameter(request, "username");
		String sjhm = RequestUtils.getStringParameter(request, "sjhm");
		params.put("start", start);
		params.put("limit", limit);
		params.put("username", username);
		params.put("sjhm", sjhm);
		List list = cjjgService.queryCjzgList(params);
		int count = cjjgService.getCjzgCount(params);
		result.put("data", list);	
		result.put("total", count);
		if (null!=page) {//新版本,传参
			int totalPage=count%limit==0?count/limit:count/limit+1;
			result.put("totalPage", totalPage);
		}
		serialize(request,response,result);
		return null;
	}
}
